package com.easy.query.test.mysql8.vo;


import com.easy.query.core.annotation.ForeignKey;
import com.easy.query.core.annotation.Navigate;
import com.easy.query.core.api.dynamic.executor.query.ConfigureArgument;
import com.easy.query.core.enums.RelationTypeEnum;
import com.easy.query.core.expression.parser.core.extra.ExtraAutoIncludeConfigure;
import com.easy.query.core.proxy.sql.Select;
import com.easy.query.test.mysql8.entity.bank.proxy.SysBankCardProxy;
import com.easy.query.test.mysql8.entity.bank.proxy.SysUserProxy;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.List;

/**
 * this file automatically generated by easy-query struct dto mapping
 * 当前文件是easy-query自动生成的 结构化dto 映射
 * {@link com.easy.query.test.mysql8.entity.bank.SysUser }
 *
 * @author xuejiaming
 * @easy-query-dto schema: normal
 */
@Data
public class SysUserDTO2 {
    private static final ExtraAutoIncludeConfigure EXTRA_AUTO_INCLUDE_CONFIGURE = SysUserProxy.TABLE.EXTRA_AUTO_INCLUDE_CONFIGURE()
            .configure(query->query.subQueryToGroupJoin(u->u.bankCards()))
            .select(o->Select.of(
                    o.bankCards().count().as("cardCount")
            ));

    private String id;
    private String name;
    private String phone;
    private Integer age;
    private LocalDateTime createTime;

    @SuppressWarnings("EasyQueryFieldMissMatch")
    private Integer cardCount;
    /**
     * 用户拥有的银行卡数
     */
    @Navigate(value = RelationTypeEnum.OneToMany)
    private List<InternalBankCards> bankCards;


    /**
     * {@link com.easy.query.test.mysql8.entity.bank.SysBank }
     */
    @Data
    public static class InternalBank {

        private String id;
        /**
         * 银行名称
         */
        private String name;
        /**
         * 成立时间
         */
        private LocalDateTime createTime;


    }


    /**
     * {@link com.easy.query.test.mysql8.entity.bank.SysBankCard }
     */
    @Data
    public static class InternalBankCards {

        private static final ExtraAutoIncludeConfigure EXTRA_AUTO_INCLUDE_CONFIGURE = SysBankCardProxy.TABLE.EXTRA_AUTO_INCLUDE_CONFIGURE()
                .where(card -> {
                    card.type().eq("储蓄卡");
                    ConfigureArgument configureArgument = card.getEntitySQLContext().getEntityExpressionBuilder().getExpressionContext().getConfigureArgument();
                    Object arg = configureArgument.getArg();
                    System.out.println("InternalBankCards:"+arg);
                })
                .select(card -> Select.of(
                        card.bank().createTime().format("yyyy-MM-dd").as("bankNameOr123")
                ));


        @SuppressWarnings("EasyQueryFieldMissMatch")
        private String bankNameOr123;

        private String id;
        private String uid;
        /**
         * 银行卡号
         */
        private String code;
        /**
         * 银行卡类型借记卡 储蓄卡
         */
        private String type;
        /**
         * 所属银行
         */
        private String bankId;
        /**
         * 用户开户时间
         */
        private LocalDateTime openTime;

        /**
         * 所属银行
         */
        @Navigate(value = RelationTypeEnum.ManyToOne)
        @ForeignKey
        private InternalBank bank;


    }

}
